package com.chx.three.mama.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

/**
 * 所有与sharePreferences类相关的操作均放在该类
 */
public class SPHelper  {
    public static final String SP_KEY_0_USER_ID="o_user_id";
    //排序列表的字符串必须为 1,2,3,4,5....
    public static final String SP_KEY_RING_LIST_SORT="ring_list_sort";
    private static  SharedPreferences sp;
    public static void initSPHelper(Context context){
        if(context==null){
            throw new IllegalArgumentException("context must not null");
        }else{
            sp=context.getSharedPreferences("mama",Context.MODE_PRIVATE);
        }
    }

    public static void setUserId(long userId){
        if(sp==null){
            throw new IllegalArgumentException("you must initSPHelper before use it");
        }
        SharedPreferences.Editor editor=sp.edit();
        editor.putLong(SP_KEY_0_USER_ID,userId);
        editor.commit();
    }

    public static long getUserId(){
        if(sp==null){
            throw new IllegalArgumentException("you must initSPHelper before use it");
        }
       return sp.getLong(SP_KEY_0_USER_ID,5);
    }

    public static void setRingListSort(String sortList){
        if(sp==null){
            throw new IllegalArgumentException("you must initSPHelper before use it");
        }
        Log.d("exchange",sortList);
        SharedPreferences.Editor editor=sp.edit();
        editor.putString(SP_KEY_RING_LIST_SORT,sortList);
        editor.commit();
    }
    public static String getRingListSort(){
        if(sp==null){
            throw new IllegalArgumentException("you must initSPHelper before use it");
        }
        return sp.getString(SP_KEY_RING_LIST_SORT,"");
    }


}
